<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">
        <h2>学校:{{school.name}}</h2>
        <h2>地址:{{school.adress}}</h2>
        <h2>校长:{{school.leader}}</h2>
        <hr>
        <h2>学生信息</h2>
        <button @click="addsex">添加一个性别</button>
        <h2>学生姓名:{{student.name}}</h2>
        <h2 v-if="student.sex">学生性别:{{student.sex}}</h2>
        <h2>学生年龄:真实{{student.age.rAge}} 对外{{student.age.sAge}}</h2>
        <ul>
            <li v-for="(f,index) in student.friends" :key="index">
                {{f.name}}--{{f.age}}
            </li>
        </ul>
    </div>

    <!-- 引入Vue -->
    <script src="../js/vue.js"></script>
    <script>
        Vue.config.productionTip = false //阻止 vue 在启动时生成生产提示。
        const vm = new Vue({
            el:'#root',
            data:{
                school:{
                    name:'华北水利水电大学',
                    adress:'龙子湖校区',
                },
                student:{
                name:'tom',
                // sex:'男',
                age:{
                    rAge:40,
                    sAge:29
                },
                friends:[{name:'jw',age:20},{name:'jh',age:20}]
                }
            },
            methods: {
                addsex(){
                    // Vue.set(this.student,'sex','男')
                    this.$set(this.student,'sex','男')
                }
            },

        })
    </script>
</body>
</html>